package com.zdhy.zoc.collect.snmp.model;

import com.zdhy.zoc.collect.ping.Pingutil;
import com.zdhy.zoc.collect.snmp.SnmpUtil;
import com.zdhy.zoc.commen.util.SystemConfig;
import org.snmp4j.smi.OID;
import org.snmp4j.smi.OctetString;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by 梁浩峰 on 2016/8/24 17:29.
 */
public class Windows extends ModelSnmp<Windows> {
    private static String sb="system.window.";
    private static String fileName="snmpmib";

    private static String hrStorageAllocationUnits = SystemConfig.getConfigInfomation(fileName, sb+"hrStorageAllocationUnits");
    private static String hrStorageSize = SystemConfig.getConfigInfomation(fileName, sb+"hrStorageSize");
    private static String hrStorageUsed = SystemConfig.getConfigInfomation(fileName, sb+"hrStorageUsed");
    private static String hrProcessorLoad = SystemConfig.getConfigInfomation(fileName, sb+"hrProcessorLoad");






    public Windows() {
    }

    public Windows(String hosts, String port, String readName, int snmpVersion) {
        super(hosts, port, readName, snmpVersion);
    }

    public Windows(String hosts, String port, String username, String userpass, int snmpVersion) {
        super(hosts, port, username, userpass, snmpVersion);
    }

    public Windows walkData(Windows ms) throws Exception {
        OID[] oids=new OID[]{new OID(ms.getHrStorageAllocationUnits()),new OID(ms.getHrStorageSize()),new OID(ms.getHrStorageUsed()),new OID(ms.getHrProcessorLoad())};
        HashMap<OID, String> map = SnmpUtil.snmpWalk(ms, oids);

        for (Map.Entry<OID,String> en:map.entrySet()
             ) {
            System.out.println(en.getKey()+"===>"+en.getValue());
        }

//        HashMap<OID, String> hrStorageAllocationUnitsMap = SnmpUtil.snmpWalk(ms,ms.getHrStorageAllocationUnits());
//        HashMap<OID, String> hrStorageSizeMap = SnmpUtil.snmpWalk(ms,ms.getHrStorageSize());
//        HashMap<OID, String> hrStorageUsedMap = SnmpUtil.snmpWalk(ms,ms.getHrStorageUsed());
//        HashMap<OID, String> hrProcessorLoadMap = SnmpUtil.snmpWalk(ms,ms.getHrProcessorLoad());

//        OID oid = new OID(hrStorageAllocationUnitsMap.size()+"");
//        int block = Integer.parseInt(hrStorageAllocationUnitsMap.get(oid));
//        int totalSize = Integer.parseInt(hrStorageSizeMap.get(oid));
//        int usedSize = Integer.parseInt(hrStorageUsedMap.get(oid));
//
//        int cpu=0;
//        for (Map.Entry<OID,String> en:hrProcessorLoadMap.entrySet()
//                ) {
//            cpu+=Integer.parseInt(en.getValue());
//        }
//
//        float totalMem=((float)totalSize*block)/1024;
//        float usedMem=((float)usedSize*block)/1024;
//
//        ms.setWorkCpu((float)cpu/4);
//        ms.setWorkmen(usedMem / totalMem*100);
//
//        if(Pingutil.isAddressAvailable(ms.getHosts())){
//            ms.setWorkStatus(0);
//        }else if(SnmpUtil.snmpPing(SnmpUtil.setting(ms))){
//            ms.setWorkStatus(0);
//        }

        return ms;
    }


    public Windows(Integer workStatus, float workCpu, float workmen) {
        super(workStatus, workCpu, workmen);
    }

    public static String getHrStorageAllocationUnits() {
        return hrStorageAllocationUnits;
    }

    public static String getHrStorageSize() {
        return hrStorageSize;
    }

    public static String getHrStorageUsed() {
        return hrStorageUsed;
    }

    public static String getHrProcessorLoad() {
        return hrProcessorLoad;
    }
}
